home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / TE32K 1.2 / windows.c < prev   
Encoding:
C/C++ Source or Header  |  1993-03-07  |  18.1 KB  |  940 lines  |  [TEXT/KAHL]

  1. #include "TE32K.h"
  2. #include <stdio.h>
  3.  
  4.  
  5. #define    INDENT    5
  6.  
  7. extern    WindowPtr        theWPtr;
  8. extern    TE32KHandle        theTEH32K;
  9. extern    ControlHandle    theVScroll,theHScroll;
  10. extern    Cursor            editCursor,waitCursor;
  11. extern    char            changed;
  12. extern    SFReply            mySFReply;
  13. extern    int                defaultFont,defaultFontSize;
  14.  
  15.  
  16. SetUpCursors()
  17. {
  18. CursHandle    hCurs;
  19.     
  20.     hCurs = GetCursor(iBeamCursor);
  21.     editCursor = **hCurs;
  22.     
  23.     hCurs = GetCursor(watchCursor);
  24.     waitCursor = **hCurs;
  25. }
  26.  
  27.  
  28.  
  29. DoMouseDown(theEvent)
  30. EventRecord    *theEvent;
  31. {
  32. WindowPtr    whichWindow;
  33. int            windowCode;
  34.  
  35.     windowCode = FindWindow(theEvent->where,&whichWindow);
  36.     
  37.     switch (windowCode = FindWindow(theEvent->where,&whichWindow)) 
  38.     {
  39.         case inMenuBar:
  40.             DoCommand(MenuSelect(theEvent->where));
  41.             break;
  42.             
  43.         case inSysWindow:
  44.             SystemClick(theEvent,whichWindow);
  45.             break;
  46.             
  47.         case inContent:
  48.             if (whichWindow != FrontWindow())
  49.                 SelectWindow(whichWindow);
  50.             
  51.             else if (IsOurWindow(whichWindow))
  52.                 DoContent(whichWindow,theEvent);
  53.             
  54.             break;
  55.         
  56.         case inDrag:
  57.             if (whichWindow != FrontWindow())
  58.                 SelectWindow(whichWindow);
  59.             
  60.             else if (IsOurWindow(whichWindow))
  61.                 DoDrag(whichWindow,theEvent);
  62.             
  63.             break;
  64.             
  65.         case inGrow:
  66.             if (whichWindow != FrontWindow())
  67.                 SelectWindow(whichWindow);
  68.             
  69.             else if (IsOurWindow(whichWindow))
  70.                 DoGrow(whichWindow,theEvent);
  71.             
  72.             break;
  73.         
  74.         case inZoomIn:
  75.         case inZoomOut:
  76.             if (whichWindow != FrontWindow())
  77.                 SelectWindow(whichWindow);
  78.             
  79.             else if (IsOurWindow(whichWindow) && TrackBox(whichWindow,theEvent->where,windowCode))
  80.                 DoZoom(whichWindow,windowCode);
  81.             
  82.             break;
  83.         
  84.         case inGoAway:
  85.             if (whichWindow != FrontWindow())
  86.                 SelectWindow(whichWindow);
  87.             
  88.             else if (IsOurWindow(whichWindow) && TrackGoAway(whichWindow,theEvent->where))
  89.                 DoCloseWindow(whichWindow);
  90.             
  91.             break;
  92.     }
  93. }
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. IsOurWindow(whichWindow)
  101. WindowPtr    whichWindow;
  102. {
  103.     if (theWPtr && whichWindow == theWPtr)
  104.         return(TRUE);
  105.     else
  106.         return(FALSE);
  107. }
  108.  
  109.  
  110.  
  111. DoActivateDeactivate(whichWindow,adFlag)
  112. WindowPtr    whichWindow;char    adFlag;
  113. {
  114. Rect            tempRect;
  115. GrafPtr            oldPort;
  116.  
  117.     if (whichWindow == theWPtr)
  118.     {
  119.         GetPort(&oldPort);
  120.         SetPort(whichWindow);
  121.         
  122.         if (adFlag)
  123.         {
  124.             HiliteControl(theVScroll,0);
  125.             HiliteControl(theHScroll,0);
  126.             TE32KActivate(theTEH32K);
  127.         }
  128.         else
  129.         {
  130.             HiliteControl(theVScroll,255);
  131.             HiliteControl(theHScroll,255);
  132.             TE32KDeactivate(theTEH32K);
  133.         }
  134.         
  135.         DrawGrowIcon(whichWindow);
  136.         
  137.         SetPort(oldPort);
  138.         
  139.         return(TRUE);
  140.     }
  141.     
  142.     else
  143.         return(FALSE);
  144. }
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. DoCloseWindow(whichWindow)
  152. WindowPtr    whichWindow;
  153. {
  154. int        userChoice;
  155.  
  156.     if (theWPtr && whichWindow==theWPtr)
  157.     {
  158.         if (changed)
  159.         {
  160.             userChoice = YesNoCancel("Save changes?",3);
  161.             
  162.             if (userChoice == 3)
  163.                 return(FALSE);
  164.             
  165.             else if (userChoice == 1 && !SaveTextFile(theTEH32K,&mySFReply))
  166.                 return(FALSE);
  167.         }        
  168.         
  169.         if (theVScroll) DisposeControl(theVScroll);
  170.         if (theHScroll) DisposeControl(theHScroll);
  171.         if (theTEH32K) TE32KDispose(theTEH32K);
  172.         if (theWPtr) DisposeWindow(theWPtr);
  173.         
  174.         theWPtr = 0L;
  175.         theTEH32K = 0L;
  176.         theVScroll = 0L;
  177.         theHScroll = 0L;
  178.         
  179.         return(TRUE);
  180.     }
  181.     
  182.     else
  183.         return(FALSE);
  184. }
  185.  
  186.  
  187.  
  188. DoGrow(whichWindow,theEvent)
  189. WindowPtr    whichWindow;EventRecord    *theEvent;
  190. {
  191. Rect            tempRect;
  192. long            newSize;
  193. GrafPtr            oldPort;
  194.  
  195.     if (theWPtr && whichWindow==theWPtr)
  196.     {
  197.         SetRect(&tempRect,100,50,32767,32767);
  198.         newSize = GrowWindow(whichWindow,theEvent->where,&tempRect);
  199.         SizeWindow(whichWindow,LoWord(newSize),HiWord(newSize),0xff);
  200.         tempRect = whichWindow->portRect;
  201.         GetPort(&oldPort);
  202.         SetPort(whichWindow);
  203.         EraseRect(&tempRect);
  204.         InvalRect(&tempRect);
  205.         
  206.         MoveControl(theVScroll,tempRect.right+1-16,tempRect.top-1);
  207.         SizeControl(theVScroll,16,whichWindow->portRect.bottom-14-(whichWindow->portRect.top-1));
  208.         
  209.         MoveControl(theHScroll,tempRect.left-1,tempRect.bottom+1-16);
  210.         SizeControl(theHScroll,whichWindow->portRect.right-14-(whichWindow->portRect.left-1),16);
  211.         
  212.         AdjustForResizedWindow();
  213.         
  214.         SetPort(oldPort);
  215.         
  216.         return(TRUE);
  217.     }
  218.     
  219.     else
  220.         return(FALSE);
  221. }
  222.  
  223.  
  224.  
  225.  
  226. DoZoom(whichWindow,windowCode)
  227. WindowPtr    whichWindow;int windowCode;
  228. {
  229. Rect            tempRect;
  230. GrafPtr            oldPort;
  231.  
  232.     if (theWPtr && whichWindow==theWPtr)
  233.     {
  234.         GetPort(&oldPort);
  235.         SetPort(whichWindow);
  236.         
  237.         tempRect = whichWindow->portRect;
  238.         EraseRect(&tempRect);
  239.         
  240.         ZoomWindow(whichWindow, windowCode, 0);
  241.         
  242.         tempRect = whichWindow->portRect;
  243.         EraseRect(&tempRect);
  244.         
  245.         MoveControl(theVScroll,tempRect.right+1-16,tempRect.top-1);
  246.         SizeControl(theVScroll,16,whichWindow->portRect.bottom-14-(whichWindow->portRect.top-1));
  247.         
  248.         MoveControl(theHScroll,tempRect.left-1,tempRect.bottom+1-16);
  249.         SizeControl(theHScroll,whichWindow->portRect.right-14-(whichWindow->portRect.left-1),16);
  250.         
  251.         AdjustForResizedWindow();
  252.         
  253.         tempRect = whichWindow->portRect;
  254.         InvalRect(&tempRect);
  255.         
  256.         SetPort(oldPort);
  257.         
  258.         return(TRUE);
  259.     }
  260.     
  261.     else
  262.         return(FALSE);
  263. }
  264.  
  265.  
  266.  
  267. DoDrag(whichWindow,theEvent)
  268. WindowPtr    whichWindow;EventRecord    *theEvent;
  269. {
  270. Rect            tempRect;
  271.  
  272.     if (theWPtr && whichWindow == theWPtr)
  273.     {
  274.         SetRect(&tempRect,screenBits.bounds.left+10,screenBits.bounds.top+25,screenBits.bounds.right-10,screenBits.bounds.bottom-25);
  275.         DragWindow(whichWindow,theEvent->where,&tempRect);
  276.         return(TRUE);
  277.     }
  278.     
  279.     else
  280.         return(FALSE);
  281. }
  282.  
  283.  
  284.  
  285.  
  286. AdjustScrollBar()
  287. {
  288. int        ctlVal,screenLines,numLines,oldVal;
  289.  
  290.     ctlVal = ((*theTEH32K)->viewRect.top - (*theTEH32K)->destRect.top)/(*theTEH32K)->lineHeight;
  291.     screenLines = ((*theTEH32K)->viewRect.bottom - (*theTEH32K)->viewRect.top)/(**theTEH32K).lineHeight;
  292.     numLines = (**theTEH32K).nLines;
  293.     
  294.     if (ctlVal > numLines-screenLines)
  295.         SetCtlMax(theVScroll,ctlVal);
  296.     else
  297.         SetCtlMax(theVScroll,(numLines-screenLines > 0) ? numLines-screenLines : 0);
  298.     
  299.     oldVal = GetCtlValue(theVScroll);
  300.     
  301.     if (oldVal != ctlVal)
  302.         SetCtlValue(theVScroll,ctlVal);
  303.     
  304.     
  305.     
  306.     ctlVal = ((*theTEH32K)->viewRect.left - (*theTEH32K)->destRect.left)/(*theTEH32K)->lineHeight;
  307.     numLines = GetCtlMax(theHScroll);
  308.     
  309.     if (ctlVal < 0)
  310.         ctlVal = 0;
  311.     else if (ctlVal > numLines)
  312.         ctlVal = numLines;
  313.     
  314.     oldVal = GetCtlValue(theHScroll);
  315.     
  316.     if (oldVal != ctlVal)
  317.         SetCtlValue(theHScroll,ctlVal);
  318. }
  319.  
  320.  
  321.  
  322. AdjustForResizedWindow()
  323. {
  324. LongRect    tempLongRect;
  325. Rect        tempRect;
  326.  
  327.     SetRect(&tempRect,(theWPtr)->portRect.left+INDENT,(theWPtr)->portRect.top+INDENT,(theWPtr)->portRect.right-15-INDENT,(theWPtr)->portRect.bottom-16-INDENT);
  328.     tempRect.bottom = tempRect.top + ((tempRect.bottom - tempRect.top)/(*theTEH32K)->lineHeight)*(*theTEH32K)->lineHeight;
  329.     
  330.     RectToLongRect(&tempRect,&((*theTEH32K)->viewRect));
  331.     
  332.     RectToLongRect(&tempRect,&((*theTEH32K)->destRect));
  333.     (*theTEH32K)->destRect.top -= (long) GetCtlValue(theVScroll)*(*theTEH32K)->lineHeight;
  334.     (*theTEH32K)->destRect.left -= (long) GetCtlValue(theHScroll)*(*theTEH32K)->lineHeight;
  335.     
  336.     (**theTEH32K).destRect.right -= 10;
  337.     
  338.     TE32KFromScrap();
  339.     
  340.     SetCursor(&waitCursor);
  341.     TE32KCalText(theTEH32K);
  342.     InitCursor();
  343.     
  344.     AdjustScrollBar();
  345. }
  346.  
  347.  
  348.  
  349. pascal void myScrollProc(theControl, theCode)
  350. ControlHandle    theControl;int    theCode;
  351. {
  352. long        scrollAmt,lines,numLines;
  353. int            controlMax,controlMin,controlVal;
  354. RgnHandle    updateRgn;
  355.     
  356.     if (theVScroll && theControl==theVScroll)
  357.     {
  358.         controlMax = GetCtlMax(theControl);
  359.         controlMin = GetCtlMin(theControl);
  360.         controlVal = GetCtlValue(theControl);
  361.         
  362.         updateRgn = NewRgn();
  363.         
  364.         switch (theCode) 
  365.         {
  366.             case inUpButton:
  367.                 if (controlVal > controlMin)
  368.                 {
  369.                     SetCtlValue(theControl,controlVal-1);
  370.                     
  371.                     TE32KScroll(0L,(long) (**theTEH32K).lineHeight,theTEH32K);
  372.                 }
  373.                 
  374.                 break;
  375.                 
  376.             case inDownButton: 
  377.                 if (controlVal < controlMax)
  378.                 {
  379.                     SetCtlValue(theControl,controlVal+1);
  380.                     
  381.                     TE32KScroll(0L,(long) -(**theTEH32K).lineHeight,theTEH32K);
  382.                 }
  383.                 
  384.                 break;
  385.     
  386.             case inPageUp: 
  387.                 if (controlVal > controlMin)
  388.                 {
  389.                     lines = ((*theTEH32K)->viewRect.bottom - (*theTEH32K)->viewRect.top)/(**theTEH32K).lineHeight;
  390.                     scrollAmt = (controlVal-lines < controlMin) ? controlVal-controlMin : lines;
  391.                     SetCtlValue(theControl,controlVal-scrollAmt);
  392.                     TE32KScroll(0L,(long) ((long) scrollAmt * (long) (**theTEH32K).lineHeight),theTEH32K);
  393.                 }
  394.                 
  395.                 break;
  396.     
  397.             case inPageDown: 
  398.                 if (controlVal < controlMax)
  399.                 {
  400.                     lines = ((**theTEH32K).viewRect.bottom - (**theTEH32K).viewRect.top)/(**theTEH32K).lineHeight;
  401.                     scrollAmt = (controlVal+lines > controlMax) ? controlMax-controlVal : lines;
  402.                     SetCtlValue(theControl,controlVal+scrollAmt);
  403.                     TE32KScroll(0L,(long) ((long) -scrollAmt * (long) (**theTEH32K).lineHeight),theTEH32K);
  404.                 }
  405.                 
  406.                 break;
  407.         }
  408.         
  409.         AdjustScrollBar();
  410.         
  411.         DisposeRgn(updateRgn);
  412.     }
  413.     
  414.     else if (theHScroll && theControl==theHScroll)
  415.     {
  416.         controlMax = GetCtlMax(theControl);
  417.         controlMin = GetCtlMin(theControl);
  418.         controlVal = GetCtlValue(theControl);
  419.         
  420.         updateRgn = NewRgn();
  421.         
  422.         switch (theCode) 
  423.         {
  424.             case inUpButton:
  425.                 if (controlVal > controlMin)
  426.                 {
  427.                     SetCtlValue(theControl,controlVal-1);
  428.                     
  429.                     TE32KScroll((long) (**theTEH32K).lineHeight,0L,theTEH32K);
  430.                 }
  431.                 
  432.                 break;
  433.                 
  434.             case inDownButton: 
  435.                 if (controlVal < controlMax)
  436.                 {
  437.                     SetCtlValue(theControl,controlVal+1);
  438.                     
  439.                     TE32KScroll((long) -(**theTEH32K).lineHeight,0L,theTEH32K);
  440.                 }
  441.                 
  442.                 break;
  443.     
  444.             case inPageUp: 
  445.                 if (controlVal > controlMin)
  446.                 {
  447.                     lines = ((*theTEH32K)->viewRect.right - (*theTEH32K)->viewRect.left)/(2 * (**theTEH32K).lineHeight);
  448.                     scrollAmt = (controlVal-lines < controlMin) ? controlVal-controlMin : lines;
  449.                     SetCtlValue(theControl,controlVal-scrollAmt);
  450.                     TE32KScroll((long) ((long) scrollAmt * (long) (**theTEH32K).lineHeight),0L,theTEH32K);
  451.                 }
  452.                 
  453.                 break;
  454.     
  455.             case inPageDown: 
  456.                 if (controlVal < controlMax)
  457.                 {
  458.                     lines = ((*theTEH32K)->viewRect.right - (*theTEH32K)->viewRect.left)/(2 * (**theTEH32K).lineHeight);
  459.                     scrollAmt = (controlVal+lines > controlMax) ? controlMax-controlVal : lines;
  460.                     SetCtlValue(theControl,controlVal+scrollAmt);
  461.                     TE32KScroll((long) -((long) scrollAmt * (long) (**theTEH32K).lineHeight),0L,theTEH32K);
  462.                 }
  463.                 
  464.                 break;
  465.         }
  466.         
  467.         AdjustScrollBar();
  468.         
  469.         DisposeRgn(updateRgn);
  470.     }
  471. }
  472.  
  473.  
  474.  
  475.  
  476.  
  477. DoContent(whichWindow,theEvent)
  478. WindowPtr    whichWindow;EventRecord    *theEvent;
  479. {
  480. GrafPtr            oldPort;
  481. ControlHandle    whichControl;
  482. int                cntlCode;
  483. long            oldVal,ctlVal;
  484. Rect            tempRect;
  485.  
  486.     if (theWPtr && whichWindow==theWPtr)
  487.     {
  488.         GetPort(&oldPort);
  489.         SetPort(whichWindow);
  490.         
  491.         LongRectToRect(&((**theTEH32K).viewRect),&tempRect);
  492.         
  493.         GlobalToLocal(&(theEvent->where));
  494.         
  495.         cntlCode = FindControl(theEvent->where,whichWindow,&whichControl);
  496.         
  497.         if (theVScroll && whichControl == theVScroll && cntlCode != 0)
  498.         {
  499.             if (cntlCode == inThumb)
  500.             {
  501.                 oldVal = GetCtlValue(whichControl);
  502.                 
  503.                 TrackControl(whichControl,theEvent->where,0L);
  504.                 
  505.                 TE32KScroll(0L,(long) ((oldVal - (long) GetCtlValue(whichControl)) * (long) (**theTEH32K).lineHeight),theTEH32K);
  506.             }
  507.             
  508.             else
  509.                 TrackControl(whichControl,theEvent->where,myScrollProc);
  510.         }
  511.         
  512.         else if (theHScroll && whichControl == theHScroll && cntlCode != 0)
  513.         {
  514.             if (cntlCode == inThumb)
  515.             {
  516.                 oldVal = GetCtlValue(whichControl);
  517.                 
  518.                 TrackControl(whichControl,theEvent->where,0L);
  519.                 
  520.                 TE32KScroll((long) ((oldVal - GetCtlValue(whichControl)) * (**theTEH32K).lineHeight),0L,theTEH32K);
  521.             }
  522.             
  523.             else
  524.                 TrackControl(whichControl,theEvent->where,myScrollProc);
  525.         }
  526.         
  527.         else if (PtInRect(theEvent->where,&tempRect))
  528.         {
  529.             if (theEvent->modifiers & shiftKey)
  530.                 TE32KClick(theEvent->where,TRUE,theTEH32K);
  531.             else
  532.                 TE32KClick(theEvent->where,FALSE,theTEH32K);
  533.         }
  534.         
  535.         SetPort(oldPort);
  536.         
  537.         return(TRUE);
  538.     }
  539.     
  540.     else
  541.         return(FALSE);
  542. }
  543.  
  544.  
  545.  
  546.  
  547. UpdateWindow(whichWindow)
  548. WindowPtr    whichWindow;
  549. {
  550. GrafPtr            oldPort;
  551. Rect            tempRect;
  552. LongRect        tempLongRect;
  553. RgnHandle        updateRgn;
  554.  
  555.     if (whichWindow != theWPtr)
  556.         return(FALSE);
  557.  
  558.     GetPort(&oldPort);
  559.     SetPort(whichWindow);
  560.     
  561.     PenNormal();
  562.     
  563.     BeginUpdate(whichWindow);
  564.     
  565.     tempRect = whichWindow->portRect;
  566.     EraseRect(&tempRect);
  567.     
  568.     if (whichWindow == theWPtr)
  569.     {
  570.         DrawGrowIcon(whichWindow);
  571.         DrawControls(whichWindow);
  572.         
  573.         updateRgn = ((WindowPeek) theWPtr)->updateRgn;
  574.         
  575.         tempLongRect.left = (**updateRgn).rgnBBox.left;
  576.         tempLongRect.top = (**updateRgn).rgnBBox.top;
  577.         tempLongRect.right = (**updateRgn).rgnBBox.right;
  578.         tempLongRect.bottom = (**updateRgn).rgnBBox.bottom;
  579.         
  580.         RectToLongRect(&tempRect,&tempLongRect);
  581.         TE32KUpdate(&tempLongRect,theTEH32K);
  582.     }
  583.     
  584.     EndUpdate(whichWindow);
  585.     
  586.     SetPort(oldPort);
  587.     
  588.     return(TRUE);
  589. }
  590.  
  591.  
  592.  
  593.  
  594.  
  595. void MyClicker()
  596. {
  597. int            controlMax,controlMin,controlVal,lineHeight;
  598. Rect        viewRect;
  599. Point        mousePoint;
  600. RgnHandle    saveClip;
  601. long        hDelta,vDelta;
  602.  
  603.     LongRectToRect(&((**theTEH32K).viewRect),&viewRect);
  604.     lineHeight = (**theTEH32K).lineHeight;
  605.  
  606.     hDelta = 0L;
  607.     vDelta = 0L;
  608.     
  609.     GetMouse(&mousePoint);
  610.     
  611.     if (!PtInRect(mousePoint,&viewRect))
  612.     {
  613.         controlMax = GetCtlMax(theVScroll);
  614.         controlMin = GetCtlMin(theVScroll);
  615.         controlVal = GetCtlValue(theVScroll);
  616.         
  617.         if (mousePoint.v>viewRect.bottom && controlVal<controlMax)
  618.         {
  619.             vDelta = -lineHeight;
  620.             SetCtlValue(theVScroll,controlVal+1);
  621.         }
  622.         
  623.         else if (mousePoint.v<viewRect.top && controlVal>controlMin)
  624.         {
  625.             vDelta = lineHeight;
  626.             SetCtlValue(theVScroll,controlVal-1);
  627.         }
  628.         
  629.         controlMax = GetCtlMax(theHScroll);
  630.         controlMin = GetCtlMin(theHScroll);
  631.         controlVal = GetCtlValue(theHScroll);
  632.         
  633.         if (mousePoint.h>viewRect.right && controlVal<controlMax)
  634.         {
  635.             hDelta = -lineHeight;
  636.             SetCtlValue(theHScroll,controlVal+1);
  637.         }
  638.         
  639.         else if (mousePoint.h<viewRect.left && controlVal>controlMin)
  640.         {
  641.             hDelta = lineHeight;
  642.             SetCtlValue(theHScroll,controlVal-1);
  643.         }
  644.     }
  645.     
  646.     if (hDelta || vDelta)
  647.     {
  648.         saveClip = NewRgn();
  649.         GetClip(saveClip);
  650.         ClipRect(&(theWPtr->portRect));
  651.         
  652.         TE32KScroll(hDelta,vDelta,theTEH32K);
  653.         
  654.         SetClip(saveClip);
  655.         DisposeRgn(saveClip);
  656.     }
  657. }
  658.  
  659.  
  660.  
  661.  
  662. void MyClickLoop()
  663. {
  664.     asm
  665.     {
  666.         movem.l        d1-d7/a0-a6,-(sp)
  667.         jsr            MyClicker
  668.         movem.l        (sp)+,d1-d7/a0-a6
  669.         moveq.l        #1,d0
  670.         rts
  671.     }
  672. }
  673.  
  674.  
  675.  
  676.  
  677. DoShowWindow()
  678. {
  679. Rect            tempRect;
  680. FontInfo        theFontInfo;
  681. LongRect        tempLongRect;
  682.  
  683.     if (theWPtr)
  684.         SelectWindow(theWPtr);
  685.         
  686.     else
  687.     {
  688.         SetRect(&tempRect,20,40,500,320);
  689.         
  690.         theWPtr = NewWindow (0L,&tempRect,"\pUntitled",TRUE,zoomDocProc,(WindowPtr) -1L,TRUE,0L);
  691.         if (StripAddress(theWPtr)==0L)
  692.         {
  693.             ErrorAlert("Insufficient memory to open window");
  694.             return;
  695.         }
  696.         
  697.         SetPort(theWPtr);
  698.         
  699.         TextFont(defaultFont);
  700.         TextSize(defaultFontSize);
  701.         TextFace(0);
  702.         TextMode(srcCopy);
  703.         
  704.         GetFontInfo(&theFontInfo);
  705.         
  706.         SetRect(&tempRect,(theWPtr)->portRect.right-15,(theWPtr)->portRect.top-1,(theWPtr)->portRect.right+1,(theWPtr)->portRect.bottom-14);
  707.         theVScroll = NewControl(theWPtr,&tempRect,"\p",TRUE,0,0,0,scrollBarProc,0L);
  708.         
  709.         if (StripAddress(theVScroll)==0L)
  710.         {
  711.             DisposeWindow(theWPtr);
  712.             theWPtr = 0L;
  713.             theVScroll = 0L;
  714.             ErrorAlert("Insufficient memory to open edit record");
  715.             return;
  716.         }
  717.         
  718.         SetRect(&tempRect,(theWPtr)->portRect.left-1,(theWPtr)->portRect.bottom+1-16,(theWPtr)->portRect.right-14,(theWPtr)->portRect.bottom+1);
  719.         theHScroll = NewControl(theWPtr,&tempRect,"\p",TRUE,0,0,255,scrollBarProc,0L);
  720.         
  721.         if (StripAddress(theVScroll)==0L)
  722.         {
  723.             DisposeWindow(theWPtr);
  724.             DisposeControl(theVScroll);
  725.             theWPtr = 0L;
  726.             theVScroll = 0L;
  727.             theHScroll = 0L;
  728.             ErrorAlert("Insufficient memory to open edit record");
  729.             return;
  730.         }
  731.         
  732.         SetRect(&(tempRect),(theWPtr)->portRect.left+INDENT,(theWPtr)->portRect.top+INDENT,(theWPtr)->portRect.right-15-INDENT,(theWPtr)->portRect.bottom-16-INDENT);
  733.         RectToLongRect(&tempRect,&tempLongRect);
  734.         theTEH32K = TE32KNew(&tempLongRect,&tempLongRect);
  735.     
  736.         if (StripAddress(theTEH32K)==0L)
  737.         {
  738.             DisposeControl(theVScroll);
  739.             DisposeControl(theHScroll);
  740.             DisposeWindow(theWPtr);
  741.             theWPtr = 0L;
  742.             theVScroll = 0L;
  743.             theHScroll = 0L;
  744.             ErrorAlert("Insufficient memory to open edit record");
  745.             return;
  746.         }
  747.         
  748.         (**theTEH32K).destRect.right -= 10;
  749.         
  750.         TE32KFromScrap();
  751.         
  752.         (*theTEH32K)->destRect.bottom = (*theTEH32K)->destRect.top + (((*theTEH32K)->destRect.bottom - (*theTEH32K)->destRect.top)/(*theTEH32K)->lineHeight)*(*theTEH32K)->lineHeight;
  753.         (*theTEH32K)->viewRect.bottom = (*theTEH32K)->viewRect.top + (((*theTEH32K)->viewRect.bottom - (*theTEH32K)->viewRect.top)/(*theTEH32K)->lineHeight)*(*theTEH32K)->lineHeight;
  754.         
  755.         (**theTEH32K).clikLoop = (ProcPtr) MyClickLoop;
  756.         
  757.         changed = FALSE;
  758.         
  759.         mySFReply.good = FALSE;
  760.     }
  761. }
  762.  
  763.  
  764.  
  765. DoKey(theChar)
  766. unsigned char    theChar;
  767. {
  768.     if (theWPtr && theWPtr == FrontWindow())
  769.     {
  770.         TE32KKey(theChar,theTEH32K);
  771.         
  772.         TE32KSelView(theTEH32K);
  773.         
  774.         changed = TRUE;
  775.         
  776.         AdjustScrollBar();
  777.         
  778.         return(TRUE);
  779.     }
  780.     
  781.     else
  782.         return(FALSE);
  783. }
  784.  
  785.  
  786. DoIdle()
  787. {
  788.     if (theWPtr && theWPtr == FrontWindow())
  789.     {
  790.         TE32KIdle(theTEH32K);
  791.         
  792.         return(TRUE);
  793.     }
  794.     
  795.     else
  796.         return(FALSE);
  797. }
  798.  
  799.  
  800.  
  801.  
  802.  
  803. MaintainCursor()
  804. {
  805. Point        pt;
  806. GrafPtr        oldPort;
  807. Rect        tempRect;
  808.  
  809.     if (theWPtr && FrontWindow() == theWPtr)
  810.     {
  811.         GetPort(&oldPort);
  812.         SetPort(theWPtr);
  813.         
  814.         SetRect(&tempRect,(theWPtr)->portRect.left+INDENT,(theWPtr)->portRect.top+INDENT,(theWPtr)->portRect.right-15-INDENT,(theWPtr)->portRect.bottom-16-INDENT);
  815.         
  816.         GetMouse(&pt);
  817.         
  818.         if (PtInRect(pt,&tempRect))
  819.             SetCursor(&editCursor);
  820.         
  821.         else
  822.             SetCursor(&arrow);
  823.         
  824.         return(TRUE);
  825.         
  826.         SetPort(oldPort);
  827.     }
  828.     
  829.     return(FALSE);
  830. }
  831.  
  832.  
  833.  
  834.  
  835. DoCut()
  836. {
  837.     if (theWPtr && FrontWindow() == theWPtr && theTEH32K)
  838.     {
  839.         SetCursor(&waitCursor);
  840.         TE32KCut(theTEH32K);
  841.         ZeroScrap();
  842.         TE32KToScrap();
  843.         InitCursor();
  844.         
  845.         changed = TRUE;
  846.         
  847.         TE32KSelView(theTEH32K);
  848.         AdjustScrollBar();
  849.         
  850.         return(TRUE);
  851.     }
  852.     
  853.     else
  854.         return(FALSE);
  855. }
  856.  
  857.  
  858.  
  859. DoCopy()
  860. {
  861.     if (theWPtr && FrontWindow() == theWPtr && theTEH32K)
  862.     {
  863.         SetCursor(&waitCursor);
  864.         TE32KCopy(theTEH32K);
  865.         ZeroScrap();
  866.         TE32KToScrap();
  867.         InitCursor();
  868.         
  869.         return(TRUE);
  870.     }
  871.     
  872.     else
  873.         return(FALSE);
  874. }
  875.  
  876.  
  877.  
  878.  
  879. DoPaste()
  880. {
  881.     if (theWPtr && FrontWindow() == theWPtr && theTEH32K)
  882.     {
  883.         SetCursor(&waitCursor);
  884.         TE32KFromScrap();
  885.         TE32KPaste(theTEH32K);
  886.         InitCursor();
  887.         
  888.         changed = TRUE;
  889.         
  890.         TE32KSelView(theTEH32K);
  891.         AdjustScrollBar();
  892.         
  893.         return(TRUE);
  894.     }
  895.     
  896.     else
  897.         return(FALSE);
  898. }
  899.  
  900.  
  901.  
  902.  
  903.  
  904. DoClear()
  905. {
  906.     if (theWPtr && FrontWindow() == theWPtr && theTEH32K)
  907.     {
  908.         SetCursor(&waitCursor);
  909.         TE32KDelete(theTEH32K);
  910.         InitCursor();
  911.         
  912.         changed = TRUE;
  913.         
  914.         TE32KSelView(theTEH32K);
  915.         AdjustScrollBar();
  916.         
  917.         return(TRUE);
  918.     }
  919.     
  920.     else
  921.         return(FALSE);
  922. }
  923.  
  924.  
  925.  
  926. DoSelectAll()
  927. {
  928.     if (theWPtr && FrontWindow() == theWPtr && theTEH32K)
  929.     {
  930.         SetCursor(&waitCursor);
  931.         TE32KSetSelect(0L,(**theTEH32K).teLength,theTEH32K);
  932.         AdjustScrollBar();
  933.         InitCursor();
  934.         
  935.         return(TRUE);
  936.     }
  937.     
  938.     else
  939.         return(FALSE);
  940. }